#include "CTradeContainer.h"
#include "CConsole.h"

CTradeContainer::CTradeContainer() {
	m_gil = 0;
	for(unsigned char slotID = 0; slotID < 8; slotID++) {
		m_itemID[slotID] = 0xFFFF;
		m_invSlotID[slotID] = 0;
		m_quantity[slotID] = 0;
	}
	m_pOwner = NULL;
}

CTradeContainer::~CTradeContainer() {
	m_pOwner = NULL;
}

unsigned long CTradeContainer::getGil() 
{
	return m_gil;
}
void CTradeContainer::setGil(unsigned long gil)
{
	CConsole::outPlain("Setting traded gil to %d",gil);
	m_gil = gil;
}

unsigned short CTradeContainer::getItemID(unsigned char slotID) {
	return m_itemID[slotID-1];
}

void CTradeContainer::setItemID(unsigned short itemID, unsigned char slotID) {
	m_itemID[slotID-1] = itemID;
}

unsigned char CTradeContainer::getInvSlotID(unsigned char slotID) {
	return m_invSlotID[slotID-1];
}

void CTradeContainer::setInvSlotID(unsigned char invSlotID, unsigned char slotID) {
	m_invSlotID[slotID-1] = invSlotID;
}

unsigned long CTradeContainer::getQuantity(unsigned char slotID) {
	return m_quantity[slotID-1];
}

void CTradeContainer::setQuantity(unsigned long quantity, unsigned char slotID) {
	m_quantity[slotID-1] = quantity;
}

unsigned long CTradeContainer::getItemQuantity(unsigned short itemID) {
	unsigned long quantity = 0;
	for(unsigned char slotID = 1; slotID <= 8; slotID++) {
		if(getItemID(slotID) == itemID)
			quantity += getQuantity(slotID);
	}
	return quantity;
}

unsigned long CTradeContainer::getTotalQuantity() {
	unsigned long quantity = 0;
	for(unsigned char slotID = 1; slotID <= 8; slotID++) {
		quantity += getQuantity(slotID);
	}
	if(getGil() > 0)
		quantity += 1;
	return quantity;
}

void CTradeContainer::setOwner(CChar * owner) {
	m_pOwner = owner;
}

CChar * CTradeContainer::getOwner() {
	return m_pOwner;
}

unsigned char CTradeContainer::getSlotCount() {
	unsigned char count = 0;
	for(unsigned char slotID = 1; slotID <= 8; slotID++) {
		if(getItemID(slotID) != 0xFFFF)
			count += 1;
	}
	return count;
}